using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using PointOfSale.Global;
using PointOfSale.Languages;

namespace PointOfSale.POSSystem
{
	public class frmFace : System.Windows.Forms.Form
	{
		private bool first = true;
		private System.Windows.Forms.Timer timer1;
		private System.ComponentModel.IContainer components;

		public frmFace()
		{
			InitializeComponent();
		}
		protected override void Dispose( bool disposing)
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmFace));
			this.timer1 = new System.Windows.Forms.Timer(this.components);
			// 
			// timer1
			// 
			this.timer1.Interval = 500;
			this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
			// 
			// frmFace
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.BackColor = System.Drawing.SystemColors.Control;
			this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
			this.ClientSize = new System.Drawing.Size(400, 249);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Name = "frmFace";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Bkapps POS";
			this.Load += new System.EventHandler(this.frmFace_Load);

		}
		#endregion

		private void timer1_Tick(object sender, System.EventArgs e)
		{
			this.stopTimer();
		}

		public void stopTimer()
		{
			if(!first)
			{
				this.timer1.Stop();
				this.Close();
			}
			else
			{
				first = false;
			}
		}

		private void pictureBox1_Click(object sender, System.EventArgs e)
		{
		
		}

		private void frmFace_Load(object sender, System.EventArgs e)
		{
			//Reade data from xml file
			clsGlobal.g_Hashtable = Language.GetData(clsGlobal.g_AppPath + "\\Languages\\Vietnamese.xml");
			clsGlobal.g_ParaHashtable = Language.GetData(clsGlobal.g_AppPath + "\\Languages\\Parameters.xml");
			
			clsGlobal.g_Tax = Convert.ToDouble(clsGlobal.g_ParaHashtable["Tax"].ToString())/100;
			clsGlobal.g_ServiceTax = Convert.ToDouble(clsGlobal.g_ParaHashtable["ServiceTax"].ToString())/100;
			clsGlobal.g_ExchangeRage = Convert.ToDouble(clsGlobal.g_ParaHashtable["ExchangeRate"].ToString());

			//Read value from INI
			cIni objIni = new cIni(clsGlobal.g_AppPath + clsGlobal.g_INI_FILE_NAME);
			clsGlobal.g_ServerIPAddress = objIni.ReadValue("ServerConfig", "ServerIPAddress", "");
			clsGlobal.g_SQLUserName = objIni.ReadValue("ServerConfig", "SQLUserName", "");
			clsGlobal.g_SQLPassword = objIni.ReadValue("ServerConfig", "SQLPassword", "");

			clsGlobal.g_HMS_ServerIPAddress = objIni.ReadValue("ServerConfig", "HMS_ServerIPAddress", "");
			clsGlobal.g_HMS_SQLUserName = objIni.ReadValue("ServerConfig", "HMS_SQLUserName", "");
			clsGlobal.g_HMS_SQLPassword = objIni.ReadValue("ServerConfig", "HMS_SQLPassword", "");
						
			//Tao ket noi den POS database
			clsGlobal.g_DatabaseName = "POS";
			clsGlobal.g_DataConn = clsGlobal.Db.ConnectToDatabase (clsGlobal.g_DatabaseName,clsGlobal.g_ServerIPAddress,clsGlobal.g_SQLUserName,clsGlobal.g_SQLPassword);

			//Tao ket noi den HMS database.
			clsGlobal.g_HMS_DatabaseName = "HMSbaokhanh";
			clsGlobal.g_HMS_DataConn = clsGlobal.Db.ConnectToDatabase(clsGlobal.g_HMS_DatabaseName, clsGlobal.g_HMS_ServerIPAddress, clsGlobal.g_HMS_SQLUserName, clsGlobal.g_HMS_SQLPassword);
			
			//Read value from Title.INI
			cIni objTitle = new cIni(clsGlobal.g_AppPath + "Title.ini");
			clsGlobal.g_CompanyName = objTitle.ReadValue("Title", "CompanyName", "");
			clsGlobal.g_CompanyAddress = objTitle.ReadValue("Title", "CompanyAddress", "");
			clsGlobal.g_CompanyMSThue = objTitle.ReadValue("Title", "CompanyMSThue", "");		
			clsGlobal.g_CompanyTel = objTitle.ReadValue("Title", "CompanyTel", "");
			clsGlobal.g_CompanyFax = objTitle.ReadValue("Title", "CompanyFax", "");
			clsGlobal.g_CompanyEmail = objTitle.ReadValue("Title", "CompanyEmail", "");
			clsGlobal.g_CompanyWebsite = objTitle.ReadValue("Title", "CompanyWebsite", "");

			this.timer1.Start();
		}
	}
}
